//
//  Test42.cpp
//  CPPTest
//
//  Created by you5 Yi on 2021/9/29.
//

#include "Test42.hpp"
#include <iostream>
#include <string>
using namespace std;
class str3 {
    string s,p;
public:
    str3(string&a, string&b) {
        s=a;
        p=b;
    }
    int find();
};

int str3::find() {
    int i=0;
    char *n=&s[0];
    long cha = s.size()-p.size();
    if (cha>=0) {
        while (i<=s.size()-p.size()) {
            int j=0;
            char *m=&p[0];
            while (j<p.size()) {
                int k=0;
                while (*m==*n) {
                    cout<<"m is "<<*m<<",n is "<<*n<<endl;
                    if (++k==p.size()) {
                        return i;
                    }
                    m++;
                    n++;
                }
                j++;
                m=&p[j];
            }
            i++;
            n++;
        }
    }
    return -1;
}

void test42() {
    string a = "ufoip";
    string b = "ip";
    str3 s = str3(a, b);
    int index = s.find();
    cout<<"index = "<<index<<endl;
}
